<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>比较大小</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <!-- 定义页面结构 -->
    <div class="compare">
        <ul>
            <div>数据1：<input type="text" v-model="num1"></div>
            <div>数据2：<input type="text" v-model="num2"></div>
            <input type="button" value="比较" @click='compare()'></li>
        </ul>
        <div class="result">{{result}}</div>
    </div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        // 定义初始数据
        data: {
            num1: '',
            num2: '',
            result: ''
        },
        // 定义事件处理函数compare
        methods: {
            compare() {
                if (!this.num1 || !this.num2) {
                    this.result = '输入的数不能为空'
                } else {
                    this.result = parseInt(this.num1) == parseInt(this.num2) ? '两个数相等' : parseInt(this.num1) > parseInt(this.num2) ? '数据1大于数据2' : '数据2大于数据1'
                }
            }
        }
    })
</script>

</body>
</html>

